package cn.luckdou.system.service.impl.oss_file;

import cn.luckdou.system.model.oss_file.OssFile;
import cn.luckdou.system.mapper.oss_file.OssFileMapper;
import cn.luckdou.system.service.oss_file.IOssFileService;
import cn.luckdou.commons.utils.AliyunOSSClientUtil;
import cn.luckdou.commons.utils.StringUtils;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * OSS文件 服务实现类
 * @author Dadou
 * @since 2018-06-05
 */
@Service
public class OssFileServiceImpl extends ServiceImpl<OssFileMapper, OssFile> implements IOssFileService {
    @Autowired
    private OssFileMapper ossFileMapper;

    @Override
    public boolean insert(String url, String name) {
        if (StringUtils.isBlank(url) || StringUtils.isBlank(name)) return false;
        String[] urls = url.split(",");
        String[] names = name.split(",");
        if (urls.length!=names.length) return false;
        for (int i=0;i<urls.length;i++){
            OssFile ossFile = new OssFile(urls[i], names[i], AliyunOSSClientUtil.bucketName,AliyunOSSClientUtil.hostAddress);
            ossFileMapper.insert(ossFile);
        }
        return true;
    }

}
